<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head th:include="public/page_css::page_css ('编辑客户地址')" />
<meta charset="UTF-8"/>
<title>Title</title>
<!-- load css -->

<link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/css/font/iconfont.css}" media="all"/>
<link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/js/layui/css/layui.css}"  media="all"/>
<link rel="stylesheet" type="text/css" th:href="@{/css/main.css}"  media="all"/>
<style>

</style>
</head>
<body>
<div id="simplewizardinwidget" class="wizard" data-target="#simplewizardinwidget-steps">
    <div class="layui-card">
        <form id="form1" class="layui-form layui-form-pane" action="">
            <div>&nbsp;</div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">详细地址</label>
                    <div class="layui-input-inline">
                        <input type="text" name="xxdz" id="xxdz" placeholder="详细地址" lay-verify="required" autocomplete="off" class="layui-input " />
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">联系人姓名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="lxr" id="lxr" placeholder="联系人姓名" autocomplete="off" class="layui-input "/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">联系人电话</label>
                    <div class="layui-input-inline">
                        <input type="text" name="lxdh" id="lxdh" placeholder="联系人电话" autocomplete="off" class="layui-input "/>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">省份</label>
                    <div class="layui-input-inline">
                        <input type="text" name="sheng" id="sheng" placeholder="省份" autocomplete="off" class="layui-input "/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">城市</label>
                    <div class="layui-input-inline">
                        <input type="text" name="shi" id="shi" placeholder="城市" autocomplete="off" class="layui-input "/>
                    </div>
                </div>
            </div>

            <input type="hidden" th:value="${sskhid}" id="sskhid" name="sskhid">
            <input type="hidden"id="id" name="id">
            <!--
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" jq-filter="submit" lay-submit="" lay-filter="addCustomer">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>-->
        </form>
        <div>
            <!--<div class="layui-col-xs24" >
                <table data-height="300" data-single-select="false"	 id="table"></table>
            </div>-->
            <div class="group-button" id="toolbar">
                <a class="layui-btn layui-btn-sm layui-btn-danger" id="delBtn">
                <i class="iconfont">&#xe626;</i> 作废
               </a>
                <a class="layui-btn layui-btn-sm layui-btn-normal " id="addbtn">
                    <i class="layui-icon">&#x1005;</i> 添加
                </a>
                <a class="layui-btn layui-btn-sm" id="savebtn">
                    <i class="layui-icon">&#x1005;</i> 保存编辑
                </a>
            </div>
            <div class="layui-col-xs24" style="max-height: 300px;overflow: auto">
                <table data-height="300" id="table1"></table>
            </div>
        </div>
    </div>
</div>
</body>
<div th:include="public/public_js::public_js"></div>
<script th:src="@{/plugin/beyond/assets/js/fuelux/wizard/wizard-custom.js}"></script>

<script>
    layui.use(['myform','zzpUtils','laydate','jquery','zzpValidation'],function () {
        zzpUtils = layui.zzpUtils
            ,laydate = layui.laydate
            ,zzpValidation = layui.zzpValidation
            ,$ = layui.jquery;
        zzpUtils.select2({
            elem:".js-data-example-ajax",
            url:"/wmsgoodstype/getWmsGoodsTypeByHzId"
        });
        window.operateEvent ={
            "click .layui-btn-primary":function (e, value, row, index) {
                alert(row.mc);
            },

            "click #editRow":function (e, value, row, index) {
                $.ajax({
                    type: 'get',
                    url: '/zxbzwms/wmsCustomerFileConsignee/findOne/'+row.id,
                    contentType: "application/json",
                    async: false,

                    success: function (data) {
                        zzpUtils.loadJsonDataToForm(data);
                        console.log(data);
                    }
                })

            },

            "click #enable":function (e, value, row, index) {
                var id = [];
                id.push(row.id);
                $.ajax({
                    type: 'post',
                    url: '/zxbzwms/wmsCustomerFileConsignee/activation',
                    contentType: "application/json",
                    async: false,
                    data: JSON.stringify({
                        ids: id,
                    }),
                    success: function (res) {

                        console.log(res);
                        setTimeout(function(){
                            /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                             parent.layer.close(index); //再执行关闭
                             console.info(data);*/
                            top.layer.msg(res.title+","+res.message);
                            zzpUtils.refreshTable("#table1");
                            //刷新父页面
                        },500);
                    }
                })
            },
            "click #deleteBtn": function (e, value, row, index) {
                console.log('触发了删除', index, row, value);
                var tabledata = $table1.bootstrapTable('getData');
                tabledata = tabledata.filter(function (item) {
                    return item.uuid !== row.uuid;
                });
                var id = [];
                id.push(row.id);
                $.ajax({
                    type: 'post',
                    url: '/zxbzwms/wmsCustomerFileConsignee/cancel',
                    contentType: "application/json",
                    async: false,
                    data: JSON.stringify({
                        ids: id,
                    }),
                    success: function (res) {
                        setTimeout(function(){
                            zzpUtils.refreshTable("#table1");
                          /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            console.info(data);*/
                            top.layer.msg(res.title+","+res.message);
                            //刷新父页面
                        },500);
                    }
                })
               /* $table1.bootstrapTable('remove', {field: 'id', values: id});
                $table1.bootstrapTable('load', tabledata);*/
            }
        }
        laydate.render({
            elem: '#test5'
            , theme: '#20a0ff'
        })
        $('#simplewizardinwidget').wizard().on('finished',function () {
            alert("结束啦");
        });
        laydate.render({
            elem: '#test1'
            ,theme: '#20a0ff'
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#test2'
            ,theme: '#20a0ff'
            ,type: 'datetime'
        });

        var $table1 = zzpUtils.table({
            elem: '#table1',
            isApi: true,
            pagination:true,
           // url: '[{wmsCustomerFileConsignee/list/0021239d70424844aba4b81dd768}]',
            url: '/wmsCustomerFileConsignee/list/'+$("#sskhid").val(),
            columns: [

                {
                    field: 'd',
                    checkbox: true,
                    clickToSelect:true
                }, {
                    field: 'num',
                    title: '序号',
                    formatter: function (value, row, index) {
                        return index+1;
                    }
                },{
                    field: 'xxdz',
                    title: '详细地址',
                },{
                    field: 'lxr',
                    title: '联系人姓名'
                },{
                    field: 'lxdh',
                    title: '联系人电话'
                },{
                    field: 'sheng',
                    title: '省份',
                },{
                    field: 'shi',
                    title: '城市',
                },{
                    field: 'caozuo',
                    title: '操作',
                    events: operateEvent,
                    formatter: operateFormatter
                }],
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
        });
        function operateFormatter(value, row, index) {
          if(row.sfyx==0){//无效
              return [
                  '<a class="layui-btn layui-btn-xs " id="enable">启用</a>',
              ].join('')
          }else{
              return [
                  '<a class="layui-btn layui-btn-danger layui-btn-xs " id="deleteBtn">作废</a>',
                  '<a class="layui-btn layui-btn-xs " id="editRow">编辑</a>'
              ].join('')
          }
        }
        //保存
        $("#savebtn").on('click', function () {
            var formObject = {};
            var formArray =$("#form1").serializeArray();
            $.each(formArray,function(i,item){
                formObject[item.name] = item.value;
            });
            var formNJson = JSON.stringify(formObject);
            alert(formJson);
            var ids = [];
            var tabledata = $table1.bootstrapTable('getData');
            console.log('tabledata', tabledata);
                $.ajax({
                    type: 'post',
                    url: '/zxbzwms/wmsCustomerFileConsignee/edit',
                    contentType: "application/json",
                    async: false,
                    data: formJson,
                    success: function (res) {
                        zzpUtils.refreshTable("#table1");
                        setTimeout(function(){
                            /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                             parent.layer.close(index); //再执行关闭
                             console.info(data);*/
                            top.layer.msg(res.title+","+res.message);

                            //刷新父页面
                        },500);
                    }

                })


            /*  if (tabledata.length <= 0) {
             layer.msg("请选择一条进行保存");
             } else {
             $.ajax({
             type: 'post',
             url: '/zxbzwms/wmsLpn/getPrintLpnCode',
             contentType: "application/json",
             async: false,
             data: JSON.stringify({
             ids: ids,
             }),
             success: function (res) {
             console.log(res);
             }
             })
             }*/
        });
        //删除多选行
        $("#delBtn").on('click', function () {
            $rows = $table1.bootstrapTable('getSelections');
            var tabledata = $table1.bootstrapTable('getData');
            if ($rows.length == 0) {
                layer.msg("请选择一条进行删除");
            } else {

                var id = [];
                $rows.forEach(function (item) {
                    id.push(item.id);
                })
                $.ajax({
                    type: 'post',
                    url: '/zxbzwms/wmsCustomerFileConsignee/cancel',
                    contentType: "application/json",
                    async: false,
                    data: JSON.stringify({
                        ids: id,
                    }),
                    success: function (res) {
                        console.info(res);
                        setTimeout(function(){
                            /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                             parent.layer.close(index); //再执行关闭
                             console.info(data);*/
                            top.layer.msg(res.title+","+res.message);
                            //刷新父页面
                        },500);
                    }
                })
              /*  $table1.bootstrapTable('remove', {field: 'id', values: id});

                $table1.bootstrapTable('load', tabledata);*/
            }
//            console.log($rows);
        });
        //添加一行
        $("#addbtn").on('click',function () {
            alert($("#sskhid").val());
            var isRepeat;
            var row={"uuid":Math.random().toString(36),"xxdz":$("#xxdz").val(),"lxr":$("#lxr").val(),"lxdh":$("#lxdh").val(),"sheng":$("#sheng").val(),"shi":$("#shi").val(),"sskhid":$("#sskhid").val()}
            $table1.bootstrapTable('append', row);
            $.ajax({
                type: 'post',
                url: '/zxbzwms/wmsCustomerFileConsignee/save',
                contentType: "application/json",
                async: false,
                data: JSON.stringify(row),
                success: function (res) {
                    zzpUtils.refreshTable("#table1");
                    setTimeout(function(){
                        /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                         parent.layer.close(index); //再执行关闭
                         console.info(data);*/
                        top.layer.msg(res.title+","+res.message);

                        //刷新父页面
                    },500);
                }
            })

            var tabledata = $table1.bootstrapTable('getData');
            console.log('tabledata', tabledata);
            zzpUtils.refreshTable("#table1");

            /* if (tabledata.length ===0) {
             $table1.bootstrapTable('append', $rows);
             } else {
             for (var i=0;i<$rows.length;i++){
             isRepeat = tabledata.every(function (item) {
             return (item.id !== $rows[i].id)
             });
             if (!isRepeat){
             break;
             }
             }
             console.log('isRepeat', isRepeat);
             if (isRepeat) {
             $table1.bootstrapTable('append', $rows);
             } else {
             layer.msg('已存在不能重复添加');
             }
             }*/
        });

        $(".inline-search-btn").on('click', function () {
            zzpUtils.refreshTable("#table");
        });
//

    });
</script>
</html>